package cn.fl.product.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.product.service.ISplBankService;
import cn.fl.product.service.ISplInfoService;
import cn.fl.product.vo.SplBankVO;
import cn.fl.product.vo.SplInfoVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.spl.facade.spl.condition.SplBankQueryCondition;
import fl.spl.facade.spl.constant.SplInfoConstant;

/**
 * @Description: 供应商开户银行信息表 控制层==
 */
@Controller
@RequestMapping("/product/splBank")
public class SplBankController extends BaseController {

	/**
	 * PrdSplBank 服务层BEAN
	 */
	@Autowired
	private ISplBankService prdSplBankService;
	
	/**
	 * 供应商服务
	 */
	@Autowired
	private ISplInfoService splInfoService;
	
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		String lxxz = request.getParameter("lxxz");
		ModelAndView view = new ModelAndView("product/splBank/prdSplBankList");
		view.addObject("splId", splId);
		view.addObject("lxxz",lxxz);
		String allowMdfBank = request.getParameter("allowMdfBank");
		view.addObject("allowMdfBank", allowMdfBank);
		String proIntId = request.getParameter("proIntId");//流程实例ID
		view.addObject("proIntId", proIntId);
		return view;
	}
	/**
	 * 到列表详情页面
	 */
	@RequestMapping(value = "/toListPageDetail.do", method = { RequestMethod.GET})
	public ModelAndView toListPageDetail(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		ModelAndView view = new ModelAndView("product/splBank/prdSplBankListDetail");
		view.addObject("splId", splId);
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String splId = request.getParameter("splId");
		String id = request.getParameter("id");
		String disable = request.getParameter("disable");//是否只修改用途
		String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
		ModelAndView view = new ModelAndView("product/splBank/prdSplBankAdd");
		String splNm = "";
		String bizTypCd = "";
		if(StringUtils.isNotEmpty(id)){
			SplBankVO splBankVO = this.prdSplBankService.selectById(Long.valueOf(id));
			if(StringUtils.isNotEmpty(isFlow)&&"1".equals(isFlow)){
				//查询供应商信息
				if(null!=splBankVO && StringUtils.isNotEmpty(splBankVO.getSplId())){
					SplInfoVO splInfoVO = this.splInfoService.selectById(splBankVO.getSplId());
					if(null!=splInfoVO && StringUtils.isNotEmpty(splInfoVO.getSplNm())){
						splNm = splInfoVO.getSplNm();
						splId = String.valueOf(splInfoVO.getId());
					}
				}
			}
			bizTypCd = splBankVO.getBizTypCd();
		}
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("splNm", splNm);
		List<KeyValueVO> bizTypCdList = this.prdSplBankService.searchBizTypCdList();
		List<KeyValueVO> purpCdList = this.prdSplBankService.searchPurpCdList();
		view.addObject("bizTypCdList", bizTypCdList);
		view.addObject("purpCdListJSON", JSON.toJSON(purpCdList));
		view.addObject("splId", splId);
		view.addObject("id", id);
		view.addObject("isFlow", isFlow);
		view.addObject("disable", disable);
		view.addObject("currOrgCd", CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.newWebLogger("加载供应商备案账号新增/修改页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetail.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
		ModelAndView view = new ModelAndView("product/splBank/prdSplBankDetail");
		
		String splId = "";
		String splNm = "";
		String bizTypCd = "";
		if(StringUtils.isNotEmpty(id)){
			SplBankVO splBankVO = this.prdSplBankService.selectById(Long.valueOf(id));
			if(StringUtils.isNotEmpty(isFlow)&&"1".equals(isFlow)){
				//查询供应商信息
				if(null!=splBankVO && StringUtils.isNotEmpty(splBankVO.getSplId())){
					SplInfoVO splInfoVO = this.splInfoService.selectById(splBankVO.getSplId());
					if(null!=splInfoVO && StringUtils.isNotEmpty(splInfoVO.getSplNm())){
						splNm = splInfoVO.getSplNm();
						splId = String.valueOf(splInfoVO.getId());
					}
				}
			}
			bizTypCd = splBankVO.getBizTypCd();
		}
		view.addObject("bizTypCd", bizTypCd);
		view.addObject("splNm", splNm);
		view.addObject("splId", splId);
		view.addObject("id", id);
		view.addObject("isFlow", isFlow);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initSplBankList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String splId = request.getParameter("splId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		SplBankQueryCondition qc = new SplBankQueryCondition();
		if (StringUtils.isNotBlank(splId)) {
			qc.setSplId(Long.valueOf(splId));
		}
		page.setCondition(qc);

		BaseLogUtils.newWebLogger("初始化供应商备案账号列表页面数据.DATA:"+JSONObject.toJSONString(page))
				.setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		Pager pager = this.prdSplBankService.searchListPage(page);
		List<SplBankVO> list = (List<SplBankVO>) pager.getResultList();
		ListPageVO<SplBankVO> listPage = new ListPageVO<SplBankVO>(list, pager.getTotalCount());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeSplBankById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("删除供应商备案账号数据,主键参数为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		
		try {
			boolean success = this.prdSplBankService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				BaseLogUtils.newWebLogger("删除供应商备案账号数据失败,ID:"+idsList.toString())
						.setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("删除供应商备案账号数据成功,ID:"+idsList.toString())
					.setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("删除供应商备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("删除供应商备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getSplBankById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("获取供应商备案账号数据,主键参数为空.").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		
		try {
			SplBankVO vo = this.prdSplBankService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.newWebLogger("获取供应商备案账号数据不存在,ID:"+id)
						.setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.info();
			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取供应商备案账号数据成功,ID:"+id)
					.setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("获取供应商备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("获取供应商备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addSplBank(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		SplBankVO entity = new SplBankVO();
		try {
			entity = this.getRequestParamForPrdSplBankAdd(request);
			Long id = this.prdSplBankService.add(entity);
			result.setData(id);
			BaseLogUtils.newWebLogger("新增供应商备案账号数据成功,ID:"+id+".DATA:"+JSONObject.toJSONString(entity))
					.setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增供应商备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("新增供应商备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifySplBank(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		SplBankVO entity = new SplBankVO();
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger("修改供应商备案账号信息,主键参数为空！.ID:"+id).setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		try {
			entity = this.getRequestParamForPrdSplBankModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.prdSplBankService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.newWebLogger("修改供应商备案账号数据失败.DATA:"+JSONObject.toJSONString(entity))
						.setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("修改供应商备案账号数据成功.DATA:"+JSONObject.toJSONString(entity))
					.setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("修改供应商备案账号数据失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("修改供应商备案账号数据失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}
	
	/**
	 * 启动流程
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.newWebLogger(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY).setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FlowConstant.FLOW_BUSINESS_TYP_SPL_BANK_ACC);//确认用不用
			flowStartParamsDTO.setModelTyp(FlowConstant.FLOW_MODEL_TYP_SPL_1);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、供应商流程大字段参数未定!");
			DataResultDTO dataResultDTO = this.prdSplBankService.addFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
			/*if(null != dataResultDTO.getInfo() && StringUtils.isNotEmpty(dataResultDTO.getInfo())){
				StringBuffer info = new StringBuffer();
				info.append(result.getInfo());
				info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR);
				info.append(dataResultDTO.getInfo());//操作人
				result.setInfo(info.toString());
			}*/
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("启动流程失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.newWebLogger("启动流程失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}
	
	//********************私有方法********************//
		/**
		 * 获取供应商参数信息
		 * @param request
		 * @return
		 * @throws BaseException
		 */
		private SplBankVO getRequestParamForPrdSplBank(HttpServletRequest request)throws BaseException{
			String rcptUnt = request.getParameter("rcptUnt");//收款方
			String purpCd = request.getParameter("purpCd");//账户用途
			String accNo = request.getParameter("accNo");//收款账号
			String bkNm = request.getParameter("bkNm");//开户行
			String bkNo = request.getParameter("bkNo");//开户行行号
			String bizTypCd = request.getParameter("bizTypCd");//账号类型
			String bkRem = request.getParameter("bkRem");//备注
			String rgnPrCd = request.getParameter("rgnPrCd");//区域-省
			String rgnCyCd = request.getParameter("rgnCyCd");//区域-市
			String contTel = request.getParameter("contTel");//联系方式

			String disable = request.getParameter("disable");
			String certNo = request.getParameter("certNo");//收款人身份证号
			String bkResTel = request.getParameter("bkResTel");//银行预留手机号

			String splId = request.getParameter("splId");
			
			String fileParams = request.getParameter("fileParams");//附件上传信息
			
			//验证参数
			if (StringUtils.isBlank(rcptUnt)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方不能为空!");
			}
			if (StringUtils.isBlank(accNo) || !StringUtils.isNumeric(accNo)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款账号不能为空,并且是数字!");
			}
			if (StringUtils.isBlank(bkNm)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行不能为空!");
			}
			if (StringUtils.isBlank(bkNo) || !StringUtils.isNumeric(bkNo)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "开户行行号不能为空,并且是数字!");
			}
			if (StringUtils.isBlank(bizTypCd)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "账号类型不能为空!");
			}else{
				if(BaseConstant.IS_YESNO_YES_STR.equals(bizTypCd) && StringUtils.isEmpty(disable)){
					if (StringUtils.isBlank(certNo) || !StringUtils.isIdCardNumber(certNo)) {
						throw new BaseException(BaseExceptionConstant.COMMON_0001, "收款方身份证号不能为空,并且是正确的身份证号格式!");
					}
					if (StringUtils.isBlank(bkResTel) || !StringUtils.checkMobileNumber(bkResTel)) {
						throw new BaseException(BaseExceptionConstant.COMMON_0001, "银行预留手机号不能为空,并且是正确的手机号格式!");
					}
				}
			}


			List<SysUlFilesRecVO> sysUlFilesRecVOList = new ArrayList<SysUlFilesRecVO>();
			//解析附件上传信息
			if(StringUtils.isNotEmpty(fileParams)){
				List<Map<String, String>> fileParamsList = new ArrayList<Map<String, String>>(); 
				JSONArray arry = JSONArray.fromObject(fileParams);
				for (int i = 0; i < arry.size(); i++) {
					net.sf.json.JSONObject jsonObject = arry.getJSONObject(i);
					Iterator<?> it = jsonObject.keys();  
					HashMap<String, String> hMap = new HashMap<String, String>();
					while (it.hasNext())  
					{  
						String key = String.valueOf(it.next());  
						String value = (String) jsonObject.get(key);  
						hMap.put(key, value);  
					} 
					fileParamsList.add(hMap);
				}
				for (Map<String, String> map : fileParamsList) {
					SysUlFilesRecVO sysUlFilesRecVO = new SysUlFilesRecVO();
					sysUlFilesRecVO.setFileNm(map.get("fileNm"));
					sysUlFilesRecVO.setFilePath(map.get("filePath"));
					sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+map.get("filePath"));
					sysUlFilesRecVO.setCrtTm(new Date());
					sysUlFilesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					//TODO 这里应该先读配置  按配置保存   这里先写死后期再改---------------Start
					sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
					sysUlFilesRecVO.setOrgCd("0000");
					sysUlFilesRecVO.setCfgCd(SplInfoConstant.SPL_BANK_FILE_UPLOAD_CFG_CD);
					sysUlFilesRecVO.setCfgDtlCd(SplInfoConstant.SPL_BANK_FILE_UPLOAD_CFG_DTL_CD);
					//TODO---------------------------------------------------------End
					//默认验证状态:未验证
					sysUlFilesRecVO.setAudStsCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_VALID_STATUS_CD_A));
					sysUlFilesRecVOList.add(sysUlFilesRecVO);
				}
			}
			
			
			SplBankVO prdSplBankVO = new SplBankVO();
			prdSplBankVO.setRcptUnt(rcptUnt.trim());
			prdSplBankVO.setPurpCd(purpCd.trim());
			prdSplBankVO.setAccNo(accNo.trim());
			prdSplBankVO.setBkNm(bkNm.trim());
			prdSplBankVO.setBkNo(bkNo.trim());
			prdSplBankVO.setBizTypCd(bizTypCd);
			prdSplBankVO.setBkRem(bkRem);
			prdSplBankVO.setRgnPrCd(rgnPrCd);
			prdSplBankVO.setRgnCyCd(rgnCyCd);
			prdSplBankVO.setSysUlFilesRecVOList(sysUlFilesRecVOList);
			if(StringUtils.isNotEmpty(splId)){
				prdSplBankVO.setSplId(Long.valueOf(splId));
			}
			prdSplBankVO.setContTel(contTel);
			prdSplBankVO.setCertNo(certNo);
			prdSplBankVO.setBkResTel(bkResTel);

			return prdSplBankVO;
		}
		
		/**
		 * 获取供应商请求参数(新增)
		 * @param request 请求
		 * @return 
		 */
		private SplBankVO getRequestParamForPrdSplBankAdd(HttpServletRequest request)throws BaseException{
			String splId = request.getParameter("splId");
			if (StringUtils.isBlank(splId)) {
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "请先维护供应商基本信息!");
			}
			SplBankVO prdSplBankVO = this.getRequestParamForPrdSplBank(request);
			if(SplInfoConstant.SPL_BIZ_TYP_CD_PUBLIC.equals(prdSplBankVO.getBizTypCd()) && CollectionUtils.isEmpty(prdSplBankVO.getSysUlFilesRecVOList())){
				throw new BaseException(BaseExceptionConstant.COMMON_0001, "对公账户必须上传企业营业执照.");
			}
			prdSplBankVO.setSplId(Long.valueOf(splId));
			prdSplBankVO.setCrtTm(new Date());
			prdSplBankVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			return prdSplBankVO;
		}
		
		/**
		 * 获取供应商请求参数(修改)
		 * @param request 请求
		 * @return 
		 */
		private SplBankVO getRequestParamForPrdSplBankModify(HttpServletRequest request)throws BaseException{
			SplBankVO prdSplBankVO = this.getRequestParamForPrdSplBank(request);
			//2017-6-27 by YAOXIURONG  避免导入账号因没有上传文件而无法修改账户用途
			/*String id = request.getParameter("id");
			
			if(SplInfoConstant.SPL_BIZ_TYP_CD_PUBLIC.equals(prdSplBankVO.getBizTypCd()) && CollectionUtils.isEmpty(prdSplBankVO.getSysUlFilesRecVOList())){
				//查询此账号下是否有文件  没有的话必须上传(企业营业执照)
				SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
				qc.setPkId(id);
				qc.setTabNm("SPL_BANK_ACC");
				qc.setSysCd(CurrentThreadContext.getCurrentSysCd());//系统代码-必须条件
				List<SysUlFilesRecVO> list = this.sysUlFilesRecService.searchList(qc);
				if(CollectionUtils.isEmpty(list)){
					throw new BaseException(BaseExceptionConstant.COMMON_0001, "对公账户必须上传企业营业执照.");
				}
			}*/
			
			prdSplBankVO.setMdfTm(new Date());
			prdSplBankVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			return prdSplBankVO;
		}
}

